<template>
    <view class="container">
        <view class="content">
            <view class="logo">
                <u-image src="/static/icon/10000.png" width="127" height="127"></u-image>
                <view class="version">当前版本：{{ version }}</view>
            </view>
            <view class="lines" @click="updateApp">
                <view class="head">检测更新</view>
                <text class="icon icon-right"></text>
            </view>
            <block v-for="(item, index) in list">
                <view class="lines" @click="$u.$MRouter.policy.to({ type: item.type })" v-if="item.type != 4 || (item.type === 4 && isVisitor)">
                    <view class="head">{{ item.name }}</view>
                    <text class="icon icon-right"></text>
                </view>
            </block>
            <view class="copyright">
                <view class="safe-area-inset-bottom">
                    <view>Copyright2020-2030</view>
                    <view>浙江超凡云仓供应链管理有限公司</view>
                </view>
            </view>
        </view>
    </view>
</template>

<script lang="ts" setup>
import { computed, ref } from 'vue'
import { useUserStore } from '@/store'
import { onReady } from '@dcloudio/uni-app'

const list = ref<Array<any>>([])

const version = ref<string | undefined>('')

const userStore = useUserStore()

const $u = computed(() => {
    return uni.$u
})

const isVisitor = computed(() => {
    return userStore.userInfo.type == 3
})

function updateApp() {
    let system = uni.getSystemInfoSync()
    // #ifdef APP-PLUS
    if (system.platform === 'android') {
        uni.$u.updateTool.updateVersionAndroid(true)
    } else if (system.platform === 'ios') {
        uni.$u.updateTool.updateVersionIOS(true)
    }
    // #endif
}
onReady(() => {
    uni.$u.$api.BaseApi.queryBaseAgreementApp().then((res: any) => {
        list.value = res
    })
    // #ifdef APP-PLUS
    plus.runtime.getProperty(plus.runtime.appid as string, wgtInfo => {
        // 优先显示补丁的版本
        version.value = wgtInfo.version || plus.runtime.version
    })
    // #endif
})
</script>

<style scoped lang="scss">
.container {
    position: relative;
}
.logo {
    height: 550rpx;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    border-bottom: 1rpx solid $uni-bg-color-grey;
    .version {
        margin-top: 60rpx;
    }
}
.lines {
    display: flex;
    justify-content: space-between;
    padding: 0 30rpx;
    line-height: 100rpx;
    height: 100rpx;
    border-bottom: 1rpx solid $uni-bg-color-grey;
    font-size: 30rpx;
}
.copyright {
    position: fixed;
    bottom: 0rpx;
    width: 100%;
    padding-bottom: 20rpx;
    font-size: 24rpx;
    line-height: 50rpx;
    text-align: center;
    background-color: $uni-bg-color-grey;
}
</style>
